package br.com.lambdacore.iterator.impl;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class LongRange implements Iterable<Long>, Iterator<Long> {

	private final long end;
	private long current;

	public LongRange(long start, long end) {
		this.current = start;
		this.end = end;
	}

	public boolean hasNext() {
		return this.current <= this.end;
	}

	public Iterator<Long> iterator() {
		return this;
	}

	public Long next() {
		if (!this.hasNext()) {
			throw new NoSuchElementException();
		}
		long ret = this.current;
		this.current++;
		return ret;
	}

	public void remove() {
		throw new UnsupportedOperationException("Not supported operation");
	}

	public static Iterable<Long> range(long end) {
		return range(0, end);
	}

	public static Iterable<Long> range(long start, long end) {
		return new LongRange(start, end);
	}

}
